﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BitPortal.Business;
using BitPortal.Models;
using BitPortal.Utils;

namespace BitPortal.Modules.ImageSlider
{
    public partial class ImageSlider : Controls.BaseUserControl
    {
        public int Height = 100;
        public int Width = 500;
        public bool AutoSize = false;
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            (this.Page as Controls.BaseFrontendPage).IncludeScriptFile("/Scripts/jquery.nivo.slider.pack.js");
            (this.Page as Controls.BaseFrontendPage).IncludeCssFile("/Modules/ImageSlider/nivo-slider.css");
            (this.Page as Controls.BaseFrontendPage).IncludeCssFile("/Modules/ImageSlider/themes/default/default.css");

            int GalleryID = ReferenceModule.GetModuleConfig("GalleryID").ToInt32TryParse();
            Height = ReferenceModule.GetModuleConfig("Height").ToInt32TryParse();
            Width = ReferenceModule.GetModuleConfig("Width").ToInt32TryParse();
            AutoSize = Convert.ToBoolean(ReferenceModule.GetModuleConfig("AutoSize"));

            RptImages.DataSource = GalleryBLL.GetByID(GalleryID).MediasInGalleries.Where(ent => ent.Media.Type == "Image").OrderByDescending(ent => ent.SortOrder);
            RptImages.DataBind();
        }
    }
}